<?php

/**
 * 代理模式：代理模式让你通过代理类去访问实际提供服务的类。可以提供其他的功能，比如检查权限，缓存结果等。
 * Class Proxy
 */

interface Door3
{
    public function open();

    public function close();
}

class LabDoor implements Door3
{
    public function open()
    {
        echo "Opening lab door\n";
    }

    public function close()
    {
        echo "Close the lab door\n";
    }
}

class SecureDoor
{
    protected $door;

    public function __construct(Door3 $door)
    {
        $this->door = $door;
    }

    public function open($password)
    {
        if ($this->authenticate($password)) {
            $this->door->open();
        } else {
            echo "Big no! It ain't possible.";
        }
    }

    public function authenticate($password)
    {
        return $password === '$ecr@et';
    }

    public function close()
    {
        return $this->door->close();
    }
}

// usage
$door = new SecureDoor(new LabDoor());
$door->open('invalid');

$door->open('$ecr@et');
$door->close();